home *** CD-ROM | disk | FTP | other *** search
- /*
- * AddDirectory.c
- * Copyright © 1992-93 Apple Computer Inc. All Rights Reserved.
- *
- * Add a directory (expressed as a FSSpec) to our private list of
- * directories. Note that AddDirectory allocates memory and, hence,
- * must not be called from an I/O completion or interrupt routine.
- */
- #include "DTSSampleDSAM.h"
-
-
- OSErr
- AddDirectory(
- register DTSSampleDSAMInfoPtr infoPtr,
- DirParamBlockPtr pb
- )
- {
- OSErr status;
- DirectoryInfoPtr newDirectory;
- RecordID rid;
- short setupRefNum;
- short pabRefNum;
- FSSpec pabSpec;
- AttributeType attributeType;
- AuthGetLocalIdentityPB authParamBlock;
-
-
- LogText('AddS', "\pAddDirectory entry");
- LogRString('AddD', pb->addDSAMDirectoryPB.directoryName);
- status = ADASGetOCESetupInfo(&rid, &setupRefNum);
- LogStatus('AddD', status, "\pADASGetOCESetupInfo");
- if (status == noErr) {
- OCECToRString(
- kPDAliasAttrTypeBody, /* Note: C-string */
- smRoman,
- (RStringPtr) &attributeType,
- kAttributeTypeMaxBytes
- );
- }
- if (status == noErr) {
- rid.local.recordName = NULL;
- rid.local.recordType = NULL;
- rid.rli = NULL;
- OCECopyCreationID(
- &pb->addDSAMDirectoryPB.directoryRecordCID,
- &rid.local.cid
- );
- pabSpec.vRefNum = 0;
- /*
- * Get the local identity. If this fails, set the local
- * identity to zero (guest).
- */
- (void) AuthGetLocalIdentity(
- (AuthParamBlockPtr) &authParamBlock,
- FALSE /* Synchronous */
- );
- LogStatus('AddD', authParamBlock.ioResult, "\pAuthGetLocalIdentity");
- if (authParamBlock.ioResult != noErr)
- authParamBlock.theLocalIdentity = 0; /* Use "guest" identity */
- status = ADASLookupAttributeValue(
- &rid,
- setupRefNum,
- authParamBlock.theLocalIdentity, /* Use owner's identity */
- kAliasBufferSize,
- FALSE, /* Don't include start point */
- &attributeType,
- OCENullCID(),
- (long) &pabSpec,
- (ForEachAttrValue) GetPABFSSpecCB
- );
- LogStatus('AddD', status, "\pADASLookupAttributeValue");
- }
- if (status == noErr) {
- status = ADASOpenPAB(
- &pabSpec,
- fsRdWrPerm,
- &pabRefNum
- );
- LogStatus('AddD', status, "\pADASOpenPAB");
- }
- if (status == noErr) {
- /*
- * Note that the directory block is created in the current heap.
- * Will this be the application heap or the system heap?
- * What happens if the application quits?
- */
- newDirectory = (DirectoryInfoPtr) NewPtrClear(sizeof (DirectoryInfo));
- status = MemError();
- LogError('AddD', status);
- if (status == noErr) {
- newDirectory->refNum = pabRefNum;
- OCECopyCreationID(
- &pb->addDSAMDirectoryPB.directoryRecordCID,
- &newDirectory->creationID
- );
- OCECopyDirDiscriminator(
- &pb->addDSAMDirectoryPB.discriminator,
- &newDirectory->discriminator
- );
- OCECopyRString(
- (RString *) pb->addDSAMDirectoryPB.directoryName,
- (RString *) &newDirectory->directoryName,
- kDirectoryNameMaxBytes
- );
- /*
- * Finally, add this directory to the list of active
- * directories. We really don't need an operating
- * system queue here, but Enqueue does what we want.
- */
- Enqueue((QElemPtr) newDirectory, &INFO.directoryQHdr);
- }
- else {
- /*
- * We couldn't allocate memory for this directory.
- * All we can do is close the PAB. Ignore any error
- * from ADASClosePAB since we have a real error now.
- */
- (void) ADASClosePAB(pabRefNum);
- }
- }
- LogStatus('AddS', status, "\pAddDirectory exit");
- if (status != noErr)
- LogRString('AddD', pb->addDSAMDirectoryPB.directoryName);
- return (status);
- }
-